class NumRange {
  final num? minValue;
  final num? maxValue;
  final bool includeMinValue;
  final bool includeMaxValue;

  const NumRange(
      {this.minValue,
      this.maxValue,
      this.includeMinValue = true,
      this.includeMaxValue = true})
      : assert(minValue != null || maxValue != null);

  bool isInRange(num value) {
    if (minValue == null) {
      if (value < maxValue! || (includeMaxValue && value == maxValue)) {
        return true;
      }
    } else if (maxValue == null) {
      if (value > minValue! || (includeMinValue && value == minValue)) {
        return true;
      }
    } else {
      if ((value > minValue! || (includeMinValue && value == minValue)) &&
          (value < maxValue! || (includeMaxValue && value == maxValue))) {
        return true;
      }
    }

    return false;
  }

  String get errorInfo {
    if (minValue == null) {
      return includeMaxValue ? "≤$maxValue" : "<$maxValue";
    } else if (maxValue == null) {
      return includeMinValue ? "≥$minValue" : ">$minValue";
    } else {
      return "${includeMinValue ? "" : ""}$minValue~${includeMaxValue ? "" : ""}$maxValue";
    }
  }

  String get errorInfoDetail {
    if (minValue == null) {
      return "须小于${includeMaxValue ? "或等于" : ""}$maxValue";
    } else if (maxValue == null) {
      return "须大于${includeMinValue ? "或等于" : ""}$minValue";
    } else {
      return "${includeMinValue ? "(含)" : ""}$minValue~${includeMaxValue ? "(含)" : ""}$maxValue之间";
    }
  }
}
